<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>博客管理</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" language="JavaScript">
	$(function() {
		$("#searchBtn").click(function(){
			var s_title = $("#s_title").val()  ;
			$("#dg").datagrid('load',{
				"title":s_title
			}) ;
		}) ;
		
		$("#updateBtn").click(function(){
			var selectedRows = $("#dg").datagrid("getSelections") ;
			if(selectedRows.length != 1) {
				$.messager.alert("系统提示","请至少选择一条数据") ;
				return false ;
			} else {
				var row = selectedRows[0] ;
				//调用父窗体的openTag函数
				window.parent.openTab('修改博客','writeBlog.jsp?blogId=' + row.blogId,'icon-writeblog') ;
				return false ;
			}
		}) ; 
		
		$("#deleteBtn").click(function(){
			var selectedRows = $("#dg").datagrid("getSelections") ;
			if(selectedRows.length == 0) {
				$.messager.alert("系统提示","请至少选择一条数据") ;
				return false ;
			} else {
				$.messager.confirm("系统提示","您确定要删除这 " + selectedRows.length + " 条数据吗？",function(r){
					if(r) {
						var strIds = [] ;
						for(var x = 0 ; x < selectedRows.length ; x ++) {
							strIds.push(selectedRows[x].blogId) ;
						}
						var ids = strIds.join(",") ;
						$.ajax({
                            type:"DELETE",
                            url:"${pageContext.request.contextPath }/admin/blog/remove/" + ids,
                            success:function(data) {
                                $.messager.alert("系统提示",data.data) ;
                                $("#dg").datagrid("load") ;
                            }
                        }) ;
					}
				}) ;
			}
			
			return false ;
		}) ;
	}) ;

	function formatterTitle(val,row) {
		return "<a target='_black' href='${pageContext.request.contextPath}/blog/articles/"+ row.blogId +"'>"+val+"</a>" ;
	}
	
	//级联属性
	function formatterBlogType(val,row) {
		return val.typeName ;
	}
</script>
</head>
<body style="margin: 1px;">
	<table id="dg" title="博客管理" class="easyui-datagrid" data-options="
		title:'用户管理',
		method:'GET',
		url:'${pageContext.request.contextPath}/admin/blog/list.do',
		fitColumns:true,
		fit:true,
		pagination:true,
		rownumbers:true,
		toolbar:'#tb'
	">
		<thead>
			<tr>
				<th field="ck" checkbox="true" align="center"></th>
				<th field="blogId" hidden></th>
				<th field="title" width="200" align="center" formatter="formatterTitle">标题</th>
				<th field="releaseDateStr" width="50" align="center">发布日期</th>
				<th field="blogType" width="50" align="center" formatter="formatterBlogType">博客类型</th>
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
			<a href="javascript:void(0)" id="updateBtn" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:void(0)" id="deleteBtn" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		</div>
		<div>
			&nbsp;标题&nbsp;<input type="text" id="s_title" size="20" />
			<a href="javascript:void(0)" id="searchBtn" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
		</div>
	</div>
</body>
</html>